<template>
	<view class="uni_box home">
		<navbar title='我的地址'>
		</navbar>
		<view class="content">
			<view class="dilist" v-for="(item,index) in list" :key="index" @click.stop="getfabu(item)">
				<view class="dione">
					<view class="dimzi">
						<text class="bti txt">{{item.name}}</text>
						<text class="phone">{{item.mobile}}</text>
					</view>
					<view class="xiu ml"  @click.stop="getedit(item)">
						<text class="xiuname">修改</text>
						<image class="icon_xgs" src="@/pages_client/static/img/icon_xgs.png" />
					</view>
				</view>
				<view class="ditwo">
					<image class="icon_dz" src="@/pages_client/static/img/icon_dz.png" />
					<text class="dimiao">{{ item.province.name+item.city.name+item.area.name+item.address }}</text>
				</view>
				<view class="dithree">
					<image class="icon_xz_s" @click.stop="moren(item,index)" v-if="item.is_default==1" src="@/pages_client/static/img/icon_dz_xz_s.png" />
					<image class="icon_xz_s"  @click.stop="moren(item,index)"  v-if="item.is_default==0" src="@/pages_client/static/img/icon_dz_xz_n.png" />
					<text class="moren"  @click.stop="moren(item,index)">默认</text>
					<view class="delview ml" @click.stop="del(item)">
						<image class="icon_sc" src="@/pages_client/static/img/delicon.png" />
						<text class="shan">删除</text>
					</view>
				</view>
			</view>
			<u-loadmore :status="status" @loadmore="loadmore" v-if="list !=''" /> 
			<u-empty text="暂无数据" mode="list" v-if="list ==''"></u-empty>
		</view>
		<view class="newbot">
			<view class="botview">
				<view class="lianxi" @click="getedit">
					<text class="lname">新增地址</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [
					{
						address:'名字'
					}
				],
				page: 1,
				limit: 10,
				last_page: 1,
				status: "loadmore",
				type:'',//fabu 就是从发布那边过来 需要传参数
			}
		},
		onLoad(option) {
			if(option.type){
				this.type = option.type
			}
			// this.getList()
		},
		onShow() {
			this.getClear()
		},
		onReachBottom: function () {
			this.loadmore();
		},
		methods: {
			async getList(){//列表数据
					let res = await this.$u.api.addressall({
					limit:this.limit,
					page:this.page
					});
					let list = res;
					this.list = this.page == 1 ? list : [...this.list, ...list];	
					if(res.list==''||Number(list.length)<Number(this.limit)){
						this.status = 'nomore';
					}
				},
				loadmore() {
					let page = this.page;
					// let last_page = this.last_page;
					if (this.status == 'loadmore') {
						this.page++;
						this.getList();
					}
				},
				getedit(item){
					this.navrouter("/pages_client/twoPage/AdressEdit?id="+item.id);
				},
				async del(item){
					//退出登陆
					let that = this
					uni.showModal({
						title: '提示',
						content: '确定删除？',
						cancelText: "取消", // 取消按钮的文字  
						confirmText: "确认", // 确认按钮的文字  
						// showCancel: false, // 是否显示取消按钮，默认为 true
						// confirmColor: '#f55850',
						// cancelColor: '#39B54A',
						success: (res) => {
						if(res.confirm) {  
							that.deltwo(item)
						} else {  
							console.log('cancel') //点击取消之后执行的代码
							}  
						} 
					})
				},
				async deltwo(item){
					let res = await this.$u.api.addressdel({
						id:item.id
					});
					this.$u.toast("操作成功");
					this.getClear()
				},
				getClear(){
					this.list = []
					this.page = 1,
					this.status= "loadmore"
					this.getList()
				},
				async moren(item,index){
					// let list = this.list
					// let res = await this.$u.api.addressdefault({
					// 	id:item.id
					// });
					// this.$u.toast("操作成功");
					// list[index].is_default = list[index].is_default==1?'0':'1'
					// this.list = list
					// this.$forceUpdate()
					this.navrouter("/pages_client/twoPage/AdressEdit?id="+item.id);
				},
				getfabu(item){
					if(this.type=='fabu'){
						let addressinfo = {}
						addressinfo = item
						//点击确定 携带参数返回
						uni.$emit('isRefreshadress',addressinfo)
						uni.navigateBack({
							delta: 1
						})
					}
					
				}
			},
			
	}
</script>

<style lang="scss" scoped>
	page{
		background-color: #f5f5f5;
	}
	.content{
		background-color: #f5f5f5;
		padding: 30rpx 30rpx 120rpx;
		.dilist{
			background: #FFFFFF;
			border-radius: 30rpx;
			padding: 30rpx;
			display: flex;
			flex-direction: column;
			margin-bottom: 30rpx;
			.dione{
				display: flex;
				flex-direction: row;
				align-items: center;
				.dimzi{
					display: flex;
					flex-direction: row;
					align-items: center;
					max-width: 88%;
					.phone{
						display: inline-block;
						margin-left: 10rpx;
						font-size: 28rpx;
						font-weight: 500;
						color: #333;
					}
				}
				.bti{
					font-weight: 800;
					font-size: 32rpx;
					color: #111111;
					max-width: 63%;
					display: block;
				}
			}
			.xiu{
			   display: flex;
			   flex-direction: row;
			   align-items: center;
			   .xiuname{
				font-weight: 500;
				font-size: 24rpx;
				color: #999999;
			   }	
			   .icon_xgs{
				width: 20rpx;
				height: 20rpx;
				margin-left: 5rpx;
			   }
			}
			
		}
		.ditwo{
			display: flex;
			flex-direction: row;
			align-items: center;
			margin: 20rpx 0 30rpx;
			.icon_dz{
				width: 32rpx;
				margin-right: 8rpx;
				height: 32rpx;
			}
			.dimiao{
				font-weight: 500;
				font-size: 30rpx;
				color: #666666;
			}
		}
		.dithree{
			display: flex;
			flex-direction: row;
			align-items: center;
			.icon_xz_s{
				width: 36rpx;
				height: 36rpx;
				margin-right: 10rpx;
			}
			.moren{
				font-weight: 400;
				font-size: 20rpx;
				color: #999999;
			}
			.delview{
				display: flex;
				flex-direction: row;
				align-items: center;
				.icon_sc{
					width: 36rpx;
					height: 36rpx;
					margin-right: 8rpx;
				}
				.shan{
					font-weight: 400;
					font-size: 28rpx;
					color: #666666;
				}
			}
		}
	}

	.newbot{
		display: flex;
		flex-direction: column;
		// height: 200rpx;
		position: fixed;
		bottom: 0;
		width: 100%;
		z-index: 100;
		.botview{
			height: 120rpx;
			background: #FFFFFF;
			width: 100%;
			
			display: flex;
			flex-direction: row;
			align-items: center;
			z-index: 10;
			// border-top: 1rpx solid #eee;
			padding: 0 30rpx 20rpx 30rpx;
			.lianxi{
				margin-left: auto;
				width: 100%;
				height: 90rpx;
				background: #483C38;
				// background: linear-gradient(90deg, #FF8F39, #FF4D43);
				border-radius: 16rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				flex-direction: column;
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				.lname{
					font-weight: bold;
					font-size: 28rpx;
					color: #FFFFFF;
				}
				.lmiao{
					font-weight: 500;
					font-size: 20rpx;
					color: #FFFFFF;
				}
			}
		}	
	}
</style>
